home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / AIncludes / fenv.a < prev    next >
Encoding:
Text File  |  1998-08-17  |  11.7 KB  |  324 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        fenv.a
  3. ;
  4. ;    Contains:    Floating-Point environment for PowerPC and 68K
  5. ;
  6. ;    Version:    Technology:    MathLib v2
  7. ;                Release:    Universal Interfaces 3.2
  8. ;
  9. ;    Copyright:    © 1987-1998 by Apple Computer, Inc., all rights reserved.
  10. ;
  11. ;    Bugs?:        For bug reports, consult the following page on
  12. ;                the World Wide Web:
  13. ;
  14. ;                    http://developer.apple.com/bugreporter/
  15. ;
  16. ;
  17.     IF &TYPE('__FENV__') = 'UNDEFINED' THEN
  18. __FENV__ SET 1
  19.  
  20.     IF &TYPE('__CONDITIONALMACROS__') = 'UNDEFINED' THEN
  21.     include 'ConditionalMacros.a'
  22.     ENDIF
  23.  
  24.     IF TARGET_OS_MAC THEN
  25. ;    A collection of functions designed to provide access to the floating
  26. ;    point environment for numerical programming. It is modeled after
  27. ;    the floating-point requirements in C9X.
  28. ;    
  29. ;    The file <fenv.h> declares many functions in support of numerical
  30. ;    programming.  It provides a set of environmental controls similar to
  31. ;    the ones found in <SANE.h>.  Programs that test flags or run under
  32. ;    non-default modes must do so under the effect of an enabling
  33. ;    "fenv_access" pragma.
  34. ;
  35.  
  36.  
  37. ; ********************************************************************************
  38. ;*                                                                                *
  39. ;*    fenv_t         is a type for representing the entire floating-point        *
  40. ;*                     environment in a single object.                              *
  41. ;*                                                                                *
  42. ;*     fexcept_t        is a type for representing the floating-point                *
  43. ;*                     exception flag state collectively.                           *
  44. ;*                                                                                *
  45. ;*******************************************************************************
  46.  
  47.     IF TARGET_CPU_PPC THEN
  48. ; typedef long                             fenv_t
  49.  
  50. ; typedef long                             fexcept_t
  51.  
  52. ;     Definitions of floating-point exception macros                          
  53.  
  54. FE_INEXACT                        EQU        $02000000
  55. FE_DIVBYZERO                    EQU        $04000000
  56. FE_UNDERFLOW                    EQU        $08000000
  57. FE_OVERFLOW                        EQU        $10000000
  58. FE_INVALID                        EQU        $20000000
  59.  
  60. ;     Definitions of rounding direction macros                                
  61.  
  62. FE_TONEAREST                    EQU        $00000000
  63. FE_TOWARDZERO                    EQU        $00000001
  64. FE_UPWARD                        EQU        $00000002
  65. FE_DOWNWARD                        EQU        $00000003
  66.     ENDIF    ; TARGET_CPU_PPC
  67.     IF TARGET_CPU_68K THEN
  68.     IF TARGET_RT_MAC_68881 THEN
  69. ; typedef long                             fexcept_t
  70.  
  71. fenv_t                    RECORD 0
  72. FPCR                     ds.l    1                ; offset: $0 (0)
  73. FPSR                     ds.l    1                ; offset: $4 (4)
  74. sizeof                     EQU *                    ; size:   $8 (8)
  75.                         ENDR
  76.  
  77. FE_INEXACT                        EQU        $00000008            ; ((long)(8))   
  78. FE_DIVBYZERO                    EQU        $00000010            ; ((long)(16))  
  79. FE_UNDERFLOW                    EQU        $00000020            ; ((long)(32))  
  80. FE_OVERFLOW                        EQU        $00000040            ; ((long)(64))  
  81. FE_INVALID                        EQU        $00000080            ; ((long)(128)) 
  82.     ELSE
  83. ; typedef short                         fexcept_t
  84.  
  85. ; typedef short                         fenv_t
  86.  
  87.  
  88. FE_INVALID                        EQU        $0001                ; ((short)(1))  
  89. FE_UNDERFLOW                    EQU        $0002                ; ((short)(2))  
  90. FE_OVERFLOW                        EQU        $0004                ; ((short)(4))  
  91. FE_DIVBYZERO                    EQU        $0008                ; ((short)(8))  
  92. FE_INEXACT                        EQU        $0010                ; ((short)(16)) 
  93.     ENDIF    ; TARGET_RT_MAC_68881
  94.  
  95. FE_TONEAREST                    EQU        $0000                ; ((short)(0))  
  96. FE_UPWARD                        EQU        $0001                ; ((short)(1))  
  97. FE_DOWNWARD                        EQU        $0002                ; ((short)(2))  
  98. FE_TOWARDZERO                    EQU        $0003                ; ((short)(3))  
  99. ;     Definitions of rounding precision macros  (68K only)                    
  100.  
  101. FE_LDBLPREC                        EQU        $0000                ; ((short)(0))  
  102. FE_DBLPREC                        EQU        $0001                ; ((short)(1))  
  103. FE_FLTPREC                        EQU        $0002                ; ((short)(2))  
  104.     ENDIF    ; TARGET_CPU_68K
  105. ;     The bitwise OR of all exception macros                                  
  106. ; *******************************************************************************
  107. ;*     The following functions provide access to the exception flags.  The      *
  108. ;*     "int" input argument can be constructed by bitwise ORs of the exception  *
  109. ;*     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  110. ;******************************************************************************
  111.  
  112. ; *******************************************************************************
  113. ;*     The function "feclearexcept" clears the supported exceptions represented *
  114. ;*     by its argument.                                                         *
  115. ;******************************************************************************
  116.  
  117. ;
  118. ; extern void feclearexcept(int excepts)
  119. ;
  120.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  121.         IMPORT_CFM_FUNCTION feclearexcept
  122.     ENDIF
  123.  
  124.  
  125.  
  126. ; *******************************************************************************
  127. ;*    The function "fegetexcept" stores a representation of the exception       *
  128. ;*     flags indicated by the argument "excepts" through the pointer argument   *
  129. ;*     "flagp".                                                                 *
  130. ;******************************************************************************
  131.  
  132. ;
  133. ; extern void fegetexcept(fexcept_t *flagp, int excepts)
  134. ;
  135.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  136.         IMPORT_CFM_FUNCTION fegetexcept
  137.     ENDIF
  138.  
  139.  
  140.  
  141. ; *******************************************************************************
  142. ;*     The function "feraiseexcept" raises the supported exceptions             *
  143. ;*     represented by its argument.                                             *
  144. ;******************************************************************************
  145.  
  146. ;
  147. ; extern void feraiseexcept(int excepts)
  148. ;
  149.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  150.         IMPORT_CFM_FUNCTION feraiseexcept
  151.     ENDIF
  152.  
  153.  
  154.  
  155. ; *******************************************************************************
  156. ;*     The function "fesetexcept" sets or clears the exception flags indicated  *
  157. ;*     by the int argument "excepts" according to the representation in the     *
  158. ;*     object pointed to by the pointer argument "flagp".  The value of         *
  159. ;*     "*flagp" must have been set by a previous call to "fegetexcept".         *
  160. ;*     This function does not raise exceptions; it just sets the state of       *
  161. ;*     the flags.                                                               *
  162. ;******************************************************************************
  163.  
  164. ;
  165. ; extern void fesetexcept(const fexcept_t *flagp, int excepts)
  166. ;
  167.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  168.         IMPORT_CFM_FUNCTION fesetexcept
  169.     ENDIF
  170.  
  171.  
  172.  
  173. ; *******************************************************************************
  174. ;*     The function "fetestexcept" determines which of the specified subset of  *
  175. ;*     the exception flags are currently set.  The argument "excepts" specifies *
  176. ;*     the exception flags to be queried as a bitwise OR of the exception       *
  177. ;*     macros.  This function returns the bitwise OR of the exception macros    *
  178. ;*     corresponding to the currently set exceptions included in "excepts".     *
  179. ;******************************************************************************
  180.  
  181. ;
  182. ; extern int fetestexcept(int excepts)
  183. ;
  184.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  185.         IMPORT_CFM_FUNCTION fetestexcept
  186.     ENDIF
  187.  
  188.  
  189.  
  190. ; *******************************************************************************
  191. ;*     The following functions provide control of rounding direction modes.     *
  192. ;******************************************************************************
  193.  
  194. ; *******************************************************************************
  195. ;*     The function "fegetround" returns the value of the rounding direction    *
  196. ;*     macro which represents the current rounding direction.                   *
  197. ;******************************************************************************
  198.  
  199. ;
  200. ; extern int fegetround(void )
  201. ;
  202.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  203.         IMPORT_CFM_FUNCTION fegetround
  204.     ENDIF
  205.  
  206.  
  207.  
  208. ; *******************************************************************************
  209. ;*     The function "fesetround" establishes the rounding direction represented *
  210. ;*     by its argument.  It returns nonzero if and only if the argument matches *
  211. ;*     a rounding direction macro.  If not, the rounding direction is not       *
  212. ;*     changed.                                                                 *
  213. ;******************************************************************************
  214.  
  215. ;
  216. ; extern int fesetround(int round)
  217. ;
  218.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  219.         IMPORT_CFM_FUNCTION fesetround
  220.     ENDIF
  221.  
  222.  
  223.  
  224. ; *******************************************************************************
  225. ;*    The following functions manage the floating-point environment, exception  *
  226. ;*    flags and dynamic modes, as one entity.                                   *
  227. ;******************************************************************************
  228.  
  229. ; *******************************************************************************
  230. ;*     The function "fegetenv" stores the current floating-point environment    *
  231. ;*     in the object pointed to by its pointer argument "envp".                 *
  232. ;******************************************************************************
  233.  
  234. ;
  235. ; extern void fegetenv(fenv_t *envp)
  236. ;
  237.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  238.         IMPORT_CFM_FUNCTION fegetenv
  239.     ENDIF
  240.  
  241.  
  242.  
  243. ; *******************************************************************************
  244. ;*     The function "feholdexcept" saves the current environment in the object  *
  245. ;*     pointed to by its pointer argument "envp", clears the exception flags,   *
  246. ;*     and clears floating-point exception enables.  This function supersedes   *
  247. ;*     the SANE function "procentry", but it does not change the current        *
  248. ;*     rounding direction mode.                                                 *
  249. ;******************************************************************************
  250.  
  251. ;
  252. ; extern int feholdexcept(fenv_t *envp)
  253. ;
  254.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  255.         IMPORT_CFM_FUNCTION feholdexcept
  256.     ENDIF
  257.  
  258.  
  259.  
  260. ; *******************************************************************************
  261. ;*     The function "fesetenv" installs the floating-point environment          *
  262. ;*     environment represented by the object pointed to by its argument         *
  263. ;*     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  264. ;*     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  265. ;*     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  266. ;******************************************************************************
  267.  
  268. ;
  269. ; extern void fesetenv(const fenv_t *envp)
  270. ;
  271.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  272.         IMPORT_CFM_FUNCTION fesetenv
  273.     ENDIF
  274.  
  275.  
  276.  
  277. ; *******************************************************************************
  278. ;*     The function "feupdateenv" saves the current exceptions into its         *
  279. ;*     automatic storage, installs the environment represented through its      *
  280. ;*     pointer argument "envp", and then re-raises the saved exceptions.        *
  281. ;*     This function, which supersedes the SANE function "procexit", can be     *
  282. ;*     used in conjunction with "feholdexcept" to write routines which hide     *
  283. ;*     spurious exceptions from their callers.                                  *
  284. ;******************************************************************************
  285.  
  286. ;
  287. ; extern void feupdateenv(const fenv_t *envp)
  288. ;
  289.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  290.         IMPORT_CFM_FUNCTION feupdateenv
  291.     ENDIF
  292.  
  293.  
  294.  
  295.     IF TARGET_CPU_68K THEN
  296. ; *******************************************************************************
  297. ;*     The following functions provide control of rounding precision.           *
  298. ;*     Because the PowerPC does not provide this capability, these functions    *  
  299. ;*     are available only for the 68K Macintosh.  Rounding precision values     *
  300. ;*     are defined by the rounding precision macros.  These functions are       *
  301. ;*     equivalent to the SANE functions getprecision and setprecision.          *
  302. ;******************************************************************************
  303.  
  304. ;
  305. ; extern int fegetprec(void )
  306. ;
  307.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  308.         IMPORT_CFM_FUNCTION fegetprec
  309.     ENDIF
  310.  
  311. ;
  312. ; extern int fesetprec(int precision)
  313. ;
  314.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  315.         IMPORT_CFM_FUNCTION fesetprec
  316.     ENDIF
  317.  
  318.     ENDIF    ; TARGET_CPU_68K
  319.     ENDIF    ; TARGET_OS_MAC
  320.  
  321.     ENDIF ; __FENV__ 
  322.  
  323.